<?php session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin','teacher','student');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
$user_id 	= $_SESSION['curuser'];	
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';


}
	$messageID	= "";
	if (isset ($_GET['id'])) {
		$messageID	= $_GET['id'];
	}
	
	$sender	= "";
	if (isset ($_GET['sen'])) {
		$sender	= $_GET['sen'];
	}

?>

<script type="text/javascript" src="../javascripts/tiny_mce/tiny_mce.js"></script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>Message Reply</title>


	<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
      
</head>
<body>

 <div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
     <p> </p>
  
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left" class="date"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
        <div id="chef_ind"> <!--open chef --><!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>
<?

						$q 		= " SELECT 						";
						$q	   .= " 	m.date, m.subject, 	    ";
						$q     .= "		u.fname, u.lname,		";
						$q	   .= "		m.message,SUBSTR(u.mname, 1, 1) AS middle";
						$q	   .= " FROM 						";
						$q     .= " 	tblmessage m,			";
						$q     .= " 	tbluser u				";						
						$q	   .= " WHERE 						";
						$q	   .= "		m.senderID = '".$sender."'		";
						$q 	   .= " AND	messageID = '".$messageID."'	";
						
						
						$msg1	= mysql_query($q);
						$msg	= mysql_fetch_assoc($msg1);
						
						$toMsg = $msg['fname']." ". $msg['middle'] .".". $msg['lname'];
						
						
						
			if(isset($_POST['create']))
{
		$userid = $_SESSION['curuser'];
		$mess = $_POST['mess'];
		$replyby = $_SESSION['us'];
		$subj = $_POST['subj'];
		$date = date("F j, Y H:i:s");
		
		
		
		if($mess == NULL OR $subj == NULL)
		{
			print '
		
		<script type="text/javascript">
		
		alert("Please complete the fields.");
		window.history.go(-1)

		</script>
		
		
		';	
		}
		else {
		
		$insert = mysql_query("INSERT INTO tblmessage (
												date,toID,
												senderID,
												subject,
												message)
												 VALUES(
												 NOW(),'$_POST[idname]',
												'$userid',
												'$subj',
												'$mess')") or die (mysql_error());
		
		print '
		
		<script type="text/javascript">
		
		window.location = "viewMessageList.php";
		</script>
		
		
		';
		
		}
}
						
						
?>
        </div>
        
      </div><!--close left -->
      
    <div class="desriptionHeader"> <!--open right-->
       <div class="post"><!--open booking -->
          <h2>Reply</h2>
            <div class="desriptionHeader"> <!--open right-->
       <div class="post2"><!--open booking -->
<form id="form5" name="form2" method="post" action="">
                    <table width="630" border="0" id="cform">
                     <input name="idname" type="hidden" id="idname"  value="<? print($sender); ?>" />
                    <tr>
                  <td height="23" colspan="2" class="label">SEND REPLY</td>
                	</tr>
                      <tr>
                        <td class="extra">To : <input name="to" readonly="readonly" type="to" id="title" size="70" value="<? print $toMsg; ?>" /></td>
                      </tr>
                      <tr>
                        <td class="extra">Title: <input name="subj" type="text" id="subj" size="70" /><? print $subj; ?></td>
                      </tr>
                      <tr>
                        <td colspan="2">&nbsp; </td>
                      </tr>
                      <tr>
                        <td colspan="2"><label>
                          <textarea name="mess" id="mess" rows="15" cols="80" style="width: 70%"><? print $mess; ?></textarea>
                        </label></td>
                      </tr>
                      <tr>
                        <td colspan="2"><label>
                            <input value='Back' type='button' id='btn' name='btn' onclick='history.go(-1); return false;'/> 
                            </label> 
                            <label> <input type="submit" name="create" id="create" value="Submit" />
                        </label></td>
                      </tr>
                    </table>
                        </form>  
                        </div>   
  </div><!--close booking -->
   </div><!--close desc -->
   


</div>
  </div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div>
</div>


</body>
</html>
